package com.tangly.codeing.service.impl;

import com.tangly.codeing.dao.SysLogDao;
import com.tangly.codeing.model.SysLog;
import com.tangly.codeing.service.SysLogService;
import com.tangly.codeing.utils.PageInfo;
import com.tangly.codeing.utils.ReturnT;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统日志
 * @author tangbing
 * @date 2019-05-08
 */
@Service
public class SysLogServiceImpl implements SysLogService {

	@Resource
	private SysLogDao sysLogDao;

	/**
    * 新增
    */
	@Override
	public ReturnT<String> insert(SysLog sysLog) {

		// valid
		if (sysLog == null) {
			return new ReturnT<>(ReturnT.FAIL_CODE, "必要参数缺失");
        }

		sysLogDao.insert(sysLog);
        return ReturnT.SUCCESS;
	}

	/**
	* 删除
	*/
	@Override
	public ReturnT<String> delete(Long id) {
		int ret = sysLogDao.delete(id);
		return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
	}

	/**
	* 批量删除
	*/
	@Override
	public ReturnT<String> batchDelete(List<String> ids) {
		int ret = sysLogDao.batchDelete(ids);
		return ret > 0 ? ReturnT.SUCCESS : ReturnT.FAIL;
	}

	/**
	* 更新
	*/
	@Override
	public ReturnT<String> update(SysLog sysLog) {
		int ret = sysLogDao.update(sysLog);
		return ret>0?ReturnT.SUCCESS:ReturnT.FAIL;
	}

	/**
	* Load查询
	*/
	@Override
	public SysLog load(Long id) {
		return sysLogDao.load(id);
	}

	/**
	* 分页查询
	*/
	@Override
	public PageInfo pageList(PageInfo pageInfo) {

		List<SysLog> pageList = sysLogDao.pageList(pageInfo);
		int totalCount = sysLogDao.pageListCount(pageInfo);

        pageInfo.setResultObject(pageList);
        pageInfo.setTotalRecord(totalCount);
        return pageInfo;
	}

}
